package com.njupt.sellsec.dao;

import com.njupt.sellsec.domain.SecGoods;
import com.njupt.sellsec.vo.GoodsFormVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: XJL
 * @Description:
 * @Date: Create in 10:48 2018/7/29
 * @Modified By:
 **/

public interface GoodsDao {
    @Select("select g.*, sg.sec_price, sg.stock_count, sg.start_date,sg.end_date from goods g left join sec_goods sg on g.id=sg.goods_id")
    List<GoodsFormVO> getGoodsVOListById();

    @Select("select g.*, sg.sec_price, sg.stock_count, sg.start_date,sg.end_date from goods g left join sec_goods sg on g.id=sg.goods_id where g.id=#{goodsId}")
    GoodsFormVO getGoodInfoById(@Param("goodsId") long goodsId);

    //防止超卖，应设置stock_count>0条件
    @Update("update sec_goods set stock_count = stock_count-1 where goods_id=#{goodsId} and stock_count>0")
    int decreaseStock(long goodsId);

    @Update("update sec_goods set stock_count = #{stockCount} where goods_id = #{goodsId}")
    public int resetStock(SecGoods g);
}
